package com.isoftstone.project.device.groundstation.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.isoftstone.project.device.groundstation.domain.UGroundstation;
import com.isoftstone.project.device.groundstation.service.IUGroundstationService;
import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Page;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.common.utils.ExcelUtil;
import com.isoftstone.framework.domain.PageData;

/**
 * 地面设备水文长观孔信息Controller
 *
 * @author guoX
 * @date 2021-02-01
 */
@Controller
@RequestMapping("/device/groundstation")
public class UGroundstationController extends BaseController {
    private String prefix = "device/groundstation";

    @Autowired
    private IUGroundstationService uGroundstationService;

    @RequiresPermissions("device:groundstation:view")
    @GetMapping()
    public String groundstation() {
        return prefix + "/groundstation_list";
    }

    /**
     * 查询地面设备水文长观孔信息列表
     */
    @RequiresPermissions("device:groundstation:list")
    @PostMapping("/uGroundstationlistPage")
    @ResponseBody
    public Object getuGroundstationlistPage(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        List<UGroundstation> list = uGroundstationService.getUGroundstationlistPage(page);
        return Tidings.success(page.getTotalResult(), list);
    }


    /**
     * 导出地面设备水文长观孔信息列表
     */
    @RequiresPermissions("device:groundstation:export")
    @PostMapping("/exportUGroundstation")
    @ResponseBody
    public Object exportUGroundstation(Page page) {
        PageData pd = this.getPageData();
        page.setPd(pd);
        page.setEntityOrField(false);
        List<UGroundstation> list = uGroundstationService.getUGroundstationlistPage(page);
        ExcelUtil<UGroundstation> util = new ExcelUtil<UGroundstation>(UGroundstation. class);
        return util.exportExcel(list, "groundstation");
    }

    /**
     * 新增地面设备水文长观孔信息
     */
    @GetMapping("/addUGroundstation")
    public String addUGroundstation() {
        return prefix + "/groundstation_add";
    }


    /**
     * 新增保存地面设备水文长观孔信息
     */
    @RequiresPermissions("device:groundstation:add")
    @PostMapping("/addUGroundstation")
    @ResponseBody
    public Object insertUGroundstation(UGroundstation uGroundstation) {
        uGroundstationService.insertUGroundstation(uGroundstation);
        return Tidings.success();

    }

    /**
     * 修改地面设备水文长观孔信息
     */
    @GetMapping("/toEditUGroundstation")
    public String toEditUGroundstation(Long id, ModelMap mmap) {
        UGroundstation uGroundstation =uGroundstationService.getUGroundstationById(id);
        mmap.put("uGroundstation", uGroundstation);
        return prefix + "/groundstation_edit";
    }

    /**
     * 修改保存地面设备水文长观孔信息
     */
    @RequiresPermissions("device:groundstation:edit")
    @PostMapping("/updateUGroundstation")
    @ResponseBody
    public Object updateUGroundstation(UGroundstation uGroundstation) {
        uGroundstationService.updateUGroundstation(uGroundstation);
        return Tidings.success();
    }

    /**
     * 删除地面设备水文长观孔信息
     */
    @RequiresPermissions("device:groundstation:remove")
    @PostMapping("/deleteUGroundstation")
    @ResponseBody
    public Object deleteUGroundstation(String id) {
        uGroundstationService.deleteUGroundstationByIds(id);
        return Tidings.success();
    }

}
